package com.ztman.rxjava.view.activity;

import android.view.View;

import com.orhanobut.logger.Logger;
import com.ztman.rxjava.R;
import com.ztman.rxjava.model.baseEntity.BaseResponser;
import com.ztman.rxjava.model.baseEntity.BaseRxBusEvent;
import com.ztman.rxjava.model.entityExtends.weather.ShowApiWeather;
import com.ztman.rxjava.model.entityExtends.weather.WeatherModelIml;
import com.ztman.rxjava.mvp.presenter.ActivityPresenter;
import com.ztman.rxjava.mvp.viewProxy.WeatherActivityProxy;
import com.ztman.rxjava.server.retrofit.OnNetRequestListener;
import com.ztman.rxjava.utils.ToastPop;

/**
 * Created by YJH on 2017/11/30.
 * 功能：显示天气信息的 activity
 */
public class WeatherActivity extends ActivityPresenter<WeatherActivityProxy> implements View.OnClickListener {

    @Override
    protected Class<WeatherActivityProxy> getPresenterClass() {
        return WeatherActivityProxy.class;
    }

    //网络数据请求分离的类
    private WeatherModelIml mWeatherModelIml;

    @Override
    protected void initData() {
        mWeatherModelIml = new WeatherModelIml();

        //atyPresenter 是 为WeatherActivity分离出去的逻辑操作功能
        atyPresenter.setOnClickListener(this, R.id.tWeather);
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void receiveRxBuxCommanders(BaseRxBusEvent baseRxBusEvent) {

    }


    @Override
    public void onClick(View v) {
        mWeatherModelIml.setWeatherParams("北京", "1", "1", "1", "1",
                new OnNetRequestListener<BaseResponser<ShowApiWeather>>() {
            @Override
            public void onRequestStart() {
                ToastPop.showShort("天气信息请求开始..");
            }

            @Override
            public void onRequestFinish() {
                ToastPop.showShort("天气信息请求完成..");
            }

            @Override
            public void onRequestSuccess(BaseResponser<ShowApiWeather> weather) {
                ToastPop.showShort("天气信息请求成功..");
                String wea = weather.showapi_res_body.toString();
                atyPresenter.setWeatherInfo(wea);
            }

            @Override
            public void onRequestFailure(Throwable t) {
                Logger.e("WeatherActivity-天气请求-" + t.toString());
                ToastPop.showShort("天气信息请求失败..");
            }
        });
    }
}
